package com.topit.show.wxapi.common;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.topit.show.wxapi.vo.AccessToken;

public class AccessTokenContainer {
	private static final Logger log = LoggerFactory.getLogger(AccessTokenContainer.class);

	private static Map<String, AccessToken> tokenMap = new ConcurrentHashMap<>();

	public static void put(String appid, AccessToken token) {
		tokenMap.put(appid, token);
	}

	public static AccessToken get(String appid) {
		AccessToken accessToken = tokenMap.get(appid);

		if (accessToken != null && !accessToken.isExpires()) {
			if (log.isDebugEnabled()) {
				log.debug("获取到缓存中的accessToken：{}", accessToken.toString());
			}
			return accessToken;
		}
		return null;
	}

	public static void refresh(String appid) {
		tokenMap.remove(appid);
	}

}
